import { JsonRequest } from './request'

class Webclient extends JsonRequest {
  constructor(payload) {
    super(payload)
  }

  static async version_info() {
    const url = '/web/webclient/version_info'
    return this.json_call(url, {})
  }
}

class Session extends JsonRequest {
  constructor(payload) {
    super(payload)
  }

  static async authenticate({ db, login, password }) {
    const url = '/web/session/authenticate'
    const payload = { db, login, password }
    const session_info = await this.json_call(url, payload)
    return session_info
  }
}

class Home extends JsonRequest {
  constructor(payload) {
    super(payload)
  }

  static async tests_mobile() {
    const url = '/web/tests/mobile'
    return await this.http_call(url, {})
  }

  static async benchmarks() {
    const url = '/web/benchmarks'
    return await this.http_call(url, {})
  }
}

const web = Home
web.webclient = Webclient
web.session = Session

export class RPC {
  constructor() {}

  static init({ baseURL, timeout }) {
    JsonRequest.baseURL = baseURL
    JsonRequest.timeout = timeout
  }
}

const rpc = RPC
rpc.web = web

export default rpc
